﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.Text.RegularExpressions;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Ajax
{
    public partial class _html2file : JumbotCms.API.FrontAjax
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }
            string html = f("html");
            string filename = f("filename");
            string pluginname = f("pluginname");
            string filetype = f("filetype");
            if (html == "" || filename == "" || filetype == "")
                Response.Write("{result :\"未知操作\"}");
            else
            {
                string fileStr = html;
                if (filetype == "html")
                {
                    fileStr = fileStr.Replace(site.Url, "");
                    Jumbot.Common.DirFile.SaveFile(fileStr, filename);
                }
                else
                {
                    fileStr = fileStr.Replace(site.Url, "");
                    fileStr = Jumbot.Common.Strings.Html2Js(fileStr);
                    if (pluginname != "")
                        fileStr = "if(typeof(Plugin" + pluginname + ")!=\"undefined\"){\r\n" + fileStr + "\r\n}";
                    Jumbot.Common.DirFile.SaveFile("/*系统于 " + System.DateTime.Now.ToString() + " 自动生成,请勿私自改动*/\r\n" + fileStr, filename);
                }
                Response.Write("{result :\"成功保存\"}");
            }

        }
    }
}